Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 13 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict'; |
||
21 | constructor(element, options = {}) { |
||
22 | this.$element = $(element); |
||
23 | this.$parent = this.$element.parent(); |
||
24 | this.$win = $(window); |
||
25 | this.$term = null; |
||
26 | let parentTagName = this.$parent.prop('tagName').toLowerCase(); |
||
27 | |||
28 | if (!options.endPoint) { |
||
29 | options.endPoint = options.endpoint; |
||
30 | } |
||
31 | |||
32 | Object.assign(this, { |
||
33 | options: Object.assign({}, options), |
||
34 | formatter: new OutputFormatter, |
||
35 | prompt: "$ ", |
||
36 | }); |
||
37 | |||
38 | this.$element.terminal(this.run.bind(this), { |
||
39 | greetings: this.greetings(), |
||
40 | onInit: (term) => { |
||
41 | this.$term = term; |
||
42 | this.loading = new Loading(term); |
||
43 | this.commands = [ |
||
44 | new Help(this, options), |
||
45 | new Artisan(this, options), |
||
46 | new Composer(this, options), |
||
47 | new Mysql(this, options), |
||
48 | new Tinker(this, options), |
||
49 | new Vi(this, options), |
||
50 | new Default(this, options), |
||
51 | ]; |
||
52 | this.run('list'); |
||
53 | }, |
||
54 | onClear: () => { |
||
55 | this.serverInfo(); |
||
56 | }, |
||
57 | prompt: this.prompt |
||
58 | }); |
||
59 | |||
60 | this.$win.on('resize', () => { |
||
61 | if (parentTagName === 'body') { |
||
62 | let width = this.$parent.width() - 20; |
||
63 | let height = this.$parent.height() - 20; |
||
64 | this.$element.width(width); |
||
65 | this.$element.height(height); |
||
66 | } else { |
||
67 | this.scrollToBottom(); |
||
68 | } |
||
69 | }).trigger('resize'); |
||
70 | |||
71 | this.$parent.on('click', () => { |
||
72 | if (this.$term) { |
||
73 | this.$term.focus(); |
||
74 | } |
||
75 | }); |
||
76 | } |
||
77 | |||
233 |